package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.PublicMapper;
import org.rcloud.io.model.Public;
import org.rcloud.io.service.PublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/12.
 */
@Service(value="PublicService")
public class PublicServiceImpl implements PublicService{
    @Autowired
    private PublicMapper publicMapper;

    @Override
    public PageVo<Public> findPublic() {

        try {
            List<Public> list = publicMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo findByEid(String eid) {

        try {
            Public aPublic = publicMapper.selectByEid(eid);
            return ResultVo.setOK(aPublic);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo savePublic(Public publ) {

        if (publ.equals("") || publ == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                publicMapper.insertSelective(publ);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo findById(int id) {

        try {
            Public aPublic = publicMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(aPublic);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updatePublic(Public publ) {

        try {
            publicMapper.updateByPrimaryKeySelective(publ);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }
}
